Device Tree

https://jung-max.github.io/2019/10/22/Device_Tree_%EB%AC%B8%EB%B2%95/
Device Tree
SoC 혹은 Board 별로 독자적인 code를 구현해야 했던 문제점
(arch/arm/mach-{BOARD}/board-*.c 파일의 복잡함)

보드 구성이 바뀌더라도 kernel 코드를 수정하지 않고 동작할 수 있도록 Device Tree를 사용

리눅스는 부팅시에 디바이스 정보를 디바이스 트리로 부터 얻는다.

리눅스 커널의 arch/arm64/boot/dts 디렉토리에 설정된 *.dts 파일을 사용
( *.dts는 커널 빌드할 때, Makefile 정보를 참조해서 생성)

┌──(csian㉿csian)-[~/…/arch/arm64/boot/dts]

└─$ ls

Makefile   altera  amlogic  arm       cavium     hisilicon  marvell    nuvoton  realtek   socionext  tesla    xilinx

actions    amazon  apm      bitmain   exynos     intel      mediatek   nvidia   renesas   sprd       ti

allwinner  amd     apple    broadcom  freescale  lg         microchip  qcom     rockchip  synaptics  toshiba

/dts-v1/;
/ {
node1 {
a-string-property = "A string";
a-string-list-property = "first string", "second string";
// hex is implied in byte arrays. no '0x' prefix is required
a-byte-data-property = [01 23 34 56];
child-node1 {
first-child-property;
second-child-property = <1>;
a-string-property = "Hello, world";
};
child-node2 {
};
};
node2 {
an-empty-property;
a-cell-property = <1 2 3 4>; /* each number (cell) is a uint32 */
child-node1 {
};
};
};
ex)
/dts-v1/;
/ {
compatible = "acme,coyotes-revenge";
#address-cells = <1>;
#size-cells = <1>;
interrupt-parent = <&intc>;
cpus {
#address-cells = <1>;
#size-cells = <0>;
cpu@0 {
compatible = "arm,cortex-a9";
reg = <0>;
};
cpu@1 {
compatible = "arm,cortex-a9";
reg = <1>;
};
};
serial@101f0000 {
compatible = "arm,pl011";
reg = <0x101f0000 0x1000 >;
interrupts = < 1 0 >;
};
serial@101f2000 {
compatible = "arm,pl011";
reg = <0x101f2000 0x1000 >;
interrupts = < 2 0 >;
};
gpio@101f3000 {
compatible = "arm,pl061";
reg = <0x101f3000 0x1000
0x101f4000 0x0010>;
interrupts = < 3 0 >;
};
intc: interrupt-controller@10140000 {
compatible = "arm,pl190";
reg = <0x10140000 0x1000 >;
interrupt-controller;
#interrupt-cells = <2>;
};
spi@10115000 {
compatible = "arm,pl022";
reg = <0x10115000 0x1000 >;
interrupts = < 4 0 >;
};
external-bus {
#address-cells = <2>
#size-cells = <1>;
ranges = <0 0 0x10100000 0x10000 // Chipselect 1, Ethernet
1 0 0x10160000 0x10000 // Chipselect 2, i2c controller
2 0 0x30000000 0x1000000>; // Chipselect 3, NOR Flash
ethernet@0,0 {
compatible = "smc,smc91c111";
reg = <0 0 0x1000>;
interrupts = < 5 2 >;
};
i2c@1,0 {
compatible = "acme,a1234-i2c-bus";
#address-cells = <1>;
#size-cells = <0>;
reg = <1 0 0x1000>;
interrupts = < 6 2 >;
rtc@58 {
compatible = "maxim,ds1338";
reg = <58>;
interrupts = < 7 3 >;
};
};
flash@2,0 {
compatible = "samsung,k8f1315ebm", "cfi-flash";
reg = <2 0 0x4000000>;
};
};
};